//
//  Me2DaySessionController.m
//  CairnStory
//  www.cairnstory.com
//
//  Created by saturna on 11. 3. 15..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Me2DaySessionController.h"
#import "Me2DaySessionDelegate.h"
#import "Me2DayOAuthViewController.h"
#import "Me2DayOAuthResult.h"




#pragma mark -
#pragma mark Me2DaySessionController

@implementation Me2DaySessionController

@synthesize delegate = m_delegate;
@synthesize me2dayTag = m_me2dayTag;



#pragma mark -
#pragma mark +++++

- (void)dealloc
{
	[super dealloc];
}


- (void)login
{
	//if (DEBUG) Me2Log(@"====> login");
	[m_delegate me2daySessionController:self
						didStartWithTag:m_me2dayTag];

	Me2DayOAuthViewController* aMe2DayOAuthViewController = [[Me2DayOAuthViewController alloc]
															 initWithAppKey:kMe2DayAppKey andDelegate:self];
	aMe2DayOAuthViewController.navigationItem.title = @"me2day login";
	[m_delegate.navigationController pushViewController:aMe2DayOAuthViewController animated:NO];
	[aMe2DayOAuthViewController release];
}


#pragma mark -
#pragma mark Me2DayOAuthViewDelegate

- (void)me2dayOAuthViewController:(Me2DayOAuthViewController*)controller
		   didLoginWithAuthResult:(Me2DayOAuthResult*)authResult
{
	m_delegate.appDelegate.me2dayOAuthResult = authResult;
	[m_delegate me2daySessionController:self
						didLoginWithTag:m_me2dayTag
						 withAuthResult:authResult];
	[m_delegate me2daySessionController:self
					   didFinishWithTag:m_me2dayTag];
}

- (void)me2dayOAuthViewController:(Me2DayOAuthViewController*)controller
		  didRejectWithAuthResult:(Me2DayOAuthResult*)authResult
{
	m_delegate.appDelegate.me2dayOAuthResult = nil;
	[m_delegate me2daySessionController:self
					   didRejectWithTag:m_me2dayTag
						 withAuthResult:authResult
							withMessage:@"me2day login rejected!!"];
	[m_delegate me2daySessionController:self
					   didFinishWithTag:m_me2dayTag];
}

- (void)me2dayOAuthViewControllerDidCancel:(Me2DayOAuthViewController*)controller
{
	m_delegate.appDelegate.me2dayOAuthResult = nil;
	[m_delegate me2daySessionController:self
					   didCancelWithTag:m_me2dayTag];
	[m_delegate me2daySessionController:self
					   didFinishWithTag:m_me2dayTag];
}

- (void)me2dayOAuthViewController:(Me2DayOAuthViewController*)controller
				 didFailWithError:(NSError*)error
{
	m_delegate.appDelegate.me2dayOAuthResult = nil;
	[m_delegate me2daySessionController:self
						 didFailWithTag:m_me2dayTag
							withMessage:@"me2day login failed!!"
							  withError:error];
	[m_delegate me2daySessionController:self
					   didFinishWithTag:m_me2dayTag];
}



@end
